import 'package:flutter/material.dart';

class DDEditField extends StatefulWidget {
  final Key key;
  final String labelText;
  final Widget editField;
  final bool required;

  const DDEditField({
    this.key,
    this.labelText = "",
    this.editField,
    this.required = false,
  })  : assert(editField != null),
        super(key: key);

  @override
  _DDEditFieldState createState() => new _DDEditFieldState();
}

class _DDEditFieldState extends State<DDEditField> {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        new SizedBox(
          width: 100.0,
          child: Padding(
            padding: EdgeInsets.all(2.0),
            child: Text(widget.labelText),
          ),
        ),
        new Expanded(
          child: new Padding(
            padding: EdgeInsets.all(2.0),
            child: widget.editField,
          ),
        ),
        _getRequire(widget.required),
      ],
    );
  }

  Widget _getRequire(bool required) {
    return new SizedBox(
      width: 20.0,
      child: Padding(
        padding: EdgeInsets.all(2.0),
        child: required
            ? Text(
                "*",
                style: TextStyle(
                  color: Colors.red,
                  fontWeight: FontWeight.bold,
                ),
              )
            : null,
      ),
    );
  }
}
